<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    用户：
    <!-- <input type="text" v-model="username" name="" id=""/> -->
    <input type="text" :value="username" @input="handleInput" name="" id="" />
    <hr>
    {{username}}
    <hr>
    <!-- v-model 等于 value属性 + @ input事件 -->
    <custom-input v-model="username" ></custom-input>
  </div>
  <script>

    Vue.component('custom-input', {
      props: ['value'],
      template: `<input :value="value" @change="hangeChange"/>`,
      methods: {
        hangeChange(event) {
          this.$emit('input', event.target.value)
        }
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {
        username: "默认值"
      },
      methods: {
        handleInput(event) {
          console.log(event)
          this.username = event.target.value;
        }
      }
    })
  </script>
</body>

</html>